Skip to content

Conversation

adrianAzoitei
Copy link
Contributor

Description

When the error field in the REST response is null (None for the python client), assume a successful execution.

From the docs:

If query failed, the error attribute contains a QueryError object. That object contains a message, an errorCode and other information about the error. See the io.trino.client.QueryError class in module trino-client in the client directory for more details.

queryError | QueryError | Non-null only if the query resulted in an error.

However, sometimes (some versions of Trino) the server returns an HTTP response with the error field present, yet with a None value. Then, an exception is thrown in the client:

Traceback (most recent call last):
  File "/OBFUSCATED/main.py", line 29, in <module>
    main()
  File "/OBFUSCATED/main.py", line 25, in main
    asyncio.run(trino_scraper.start())
  File "/root/.pyenv/versions/3.11.10/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/root/.pyenv/versions/3.11.10/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.pyenv/versions/3.11.10/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/OBFUSCATED/scrapers.py", line 165, in start
    cur.execute(
  File "/OBFUSCATED/.venv/lib/python3.11/site-packages/trino/dbapi.py", line 585, in execute
    self._iterator = iter(self._query.execute())
                          ^^^^^^^^^^^^^^^^^^^^^
  File "/OBFUSCATED/.venv/lib/python3.11/site-packages/trino/client.py", line 814, in execute
    status = self._request.process(response)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/OBFUSCATED/.venv/lib/python3.11/site-packages/trino/client.py", line 619, in process
    raise self._process_error(response["error"], response.get("id"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/OBFUSCATED/.venv/lib/python3.11/site-packages/trino/client.py", line 584, in _process_error
    error_type = error["errorType"]
                 ~~~~~^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

Non-technical explanation

Sometimes (some versions of Trino) the server returns an HTTP response with the error field present, yet with a None value.

Release notes

(x) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

Fixes #511

Copy link

cla-bot bot commented Jan 6, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@martint
Copy link
Member

martint commented Jan 19, 2025

@cla-bot check

Copy link

cla-bot bot commented Jan 19, 2025

The cla-bot has been summoned, and re-checked this pull request!

@wendigo wendigo merged commit 3c745f7 into trinodb:master Jan 20, 2025
12 checks passed
GaetanLepage pushed a commit to NixOS/nixpkgs that referenced this pull request Apr 24, 2025
* Improve handling of query results containing `null` values for
  the error field.
  ([#512](trinodb/trino-python-client#512))
* Fix accessing spooled segments on S3 when authentication to the
  Trino cluster is used.
  ([#525](trinodb/trino-python-client#525))
* Simplify `segment` cursor API to make it easier to iterate over spooled
  segments.
  ([#525](trinodb/trino-python-client#525))
mkg20001 pushed a commit to mkg20001/nixpkgs that referenced this pull request Apr 29, 2025
* Improve handling of query results containing `null` values for
  the error field.
  ([NixOS#512](trinodb/trino-python-client#512))
* Fix accessing spooled segments on S3 when authentication to the
  Trino cluster is used.
  ([NixOS#525](trinodb/trino-python-client#525))
* Simplify `segment` cursor API to make it easier to iterate over spooled
  segments.
  ([NixOS#525](trinodb/trino-python-client#525))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Uncaught exception when error field is None

3 participants